package libs;


/**
 *              This class represents a subject.
 * @author      Jan Papousek
 * @version     2009-03-02
 */
public class Subject {

    /**
     *          Subject code.
     */
    private String code;

    /**
     *          Subject name.
     */
    private String name;


    /**
     * @param   name    Subject name.
     * @param   code    Subject code.
     * @throws  NullPointerException if the name or the code is null.
     */
    public Subject (String name, String code) {
        if (name == null) {
            throw new NullPointerException("Parameter 'name' is null.");
        }
        if (code == null) {
            throw new NullPointerException("Parameter 'code' is null.");
        }
        this.name = name;
        this.code = code;
    }

    /**
     *          It returns a subject code.
     * 
     * @return  Subject code.
     */
    public String getCode () {
        return code;
    }

    /**
     *          It returns a subject name.
     * 
     * @return  Subject name.
     */
    public String getName () {
        return name;
    }

    /**
     *          The subjects are the same if their codes are the same.
     */
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Subject)) {
            return false;
        }
        Subject sub = (Subject)o;
        return (sub.getCode().equals(this.getCode()));
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 67 * hash + (this.code != null ? this.code.hashCode() : 0);
        return hash;
    }

}